﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using System.Xml;

namespace DemoGame1
{
    public class Credit : Menu
    {
        int _menuItems;

        KeyboardState oldState;
        Color Normal = Color.Silver;
        Color Hilite = Color.Red;
        MyButton background;

        private int selectedIndex = 0;
        myGame game;
        public Credit(myGame _g, string strXML)
        {
            game = _g;
            myButtons = new List<MyButton>();
            XmlDocument doc = new XmlDocument();
            doc.Load(strXML);
            XmlElement backGround = (XmlElement)doc.SelectSingleNode("//BackGround");
            //MyButton backGroundButton;
            if (backGround != null)
            {
                background = new MyButton(_g.Content, backGround);
            }
            //add char
            XmlElement buttons = (XmlElement)doc.SelectSingleNode("//Buttons");
            foreach (XmlNode button in buttons.ChildNodes)
            {
                MyButton bt = new MyButton(_g.Content, (XmlElement)button);
                myButtons.Add(bt);
            }
            _menuItems = 1;
        }

        public override void HandleKeyInput()
        {
            KeyboardState newState = Keyboard.GetState();
            if (newState.IsKeyDown(Keys.Back))
            {
                if (!oldState.IsKeyDown(Keys.Back))
                {
                    myGame.currentScreen = CurrentScreen.StartMenu;
                }

            }
            oldState = newState;
        }

        public override void Update(GameTime gameTime)
        {
            HandleKeyInput();
            myButtons[0].Update(gameTime);
            if (myButtons[0].isEndFrame())
            {
                myButtons[1].NextFrame();
            }
        }

        public override void Draw(SpriteBatch sb, GameTime gameTime)
        {
            if (background != null)
                background.Draw(sb, gameTime);

            for (int i = 0; i < myButtons.Count; i++)
            {
                myButtons[i].Draw(sb, gameTime);
            }
        }

    }
}
